package com.game.character;

import android.graphics.Point;

import com.game.framwork.itf.Graphics;
import com.game.object.AnimateObject;
import com.game.tiledmap.DamgeReceive;
import com.game.tiledmap.DamgeReceiveManager;
import com.game_ltdd.Resrouce;

public class Character extends AnimateObject {

	public TypeCharacter.TypeObject type;
	public int currState;
	public int maxHP;
	public int maxMP;

	public boolean isPaintDameReceive;
	public int rangeDamge;
	public int minimumDamge;
	public int dameReceive;

	public int def;

	public float currentSpeed;
	public float runSpeed;
	public float maxRunSpeed;

	public boolean isExplore;
	public Point mapPos;

	public boolean isChangeDir;
	public float timeDelayShot;
	public float timeMaxDelayShot;

	public Character() {
		maxHP = 100;
		maxMP = 100;
		minimumDamge = 20;
		rangeDamge = 10;
		def = 0;
		runSpeed = 200.0f;
		maxRunSpeed = 500.0f;
		canCollision = true;
	}

	public void setPosInMap(int row, int col) {
		Point pos = new Point(this.tiledMap.mapPos.x + this.tiledMap.cellSize
				* col, this.tiledMap.mapPos.y + this.tiledMap.cellSize * row);
		this.position = new Point(pos);
	}

	@Override
	public void updateInternal(float deltaTime) {
		if (maxHP > 0) {
			if (dameReceive > 0) {
				DamgeReceive damgeReceive = new DamgeReceive(dameReceive, x + 15, y - 5, tiledMap); 
				DamgeReceiveManager.getInstance().addDameReceive(damgeReceive);
				maxHP -= dameReceive;
				dameReceive = 0;
			}
			if (maxHP <= 0) {
				isDying = true;
				Resrouce.playerdie.play(1, 0);
			}
		}
		super.updateInternal(deltaTime);
	}

	@Override
	public void paintInternal(Graphics g) {
		super.paintInternal(g);
	}

	public void findStandState(int currentState) {
		switch (currentState) {
		case MOVE_LEFT:
			changeAnimation("Stand Left");
			break;
		case MOVE_RIGHT:
			changeAnimation("Stand Right");
			break;
		case MOVE_TOP:
			changeAnimation("Stand Top");
			break;
		case MOVE_BOTTOM:
			changeAnimation("Stand Bot");
			break;
		}
	}

	public void move(float speed) {
		switch (currState) {
		case MOVE_LEFT:
			Move(velocity.x + (int) speed, 0);
			break;
		case MOVE_RIGHT:
			Move(-velocity.x + (int) speed, 0);
			break;
		case MOVE_TOP:
			Move(0, -velocity.y + (int) speed);
			break;
		case MOVE_BOTTOM:
			Move(0, velocity.y + (int) speed);
			break;
		}
	}
}
